package com.tgy.leetcode;

/**
 * @Author: tgy
 * @Date: 12/26/20 8:17 PM
 *
 *  https://leetcode-cn.com/problems/reverse-integer/
 */
public class _7_整数反转 {

    public int reverse(int x) {

        int result = 0,preResult;
        int bit;
        while (x != 0) {

            bit = x % 10;

            preResult = result;

            result = result * 10 + bit;

            if ((result - bit) / 10 != preResult) {

                return 0;
            }

            x/= 10;
        }


        return result;
    }
}
